<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.44">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #ad140d}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #ad140d}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #001bb9}
span.s1 {color: #001bb9}
span.s2 {color: #2c7014}
span.s3 {color: #000000}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1">//SLUGens released under the GNU GPL as extensions for SuperCollider 3, by Nick Collins, http://www.informatics.sussex.ac.uk/users/nc81/</p>
<p class="p2"><br></p>
<p class="p3"><b>WeaklyNonlinear<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Weakly Nonlinear Oscillator</b></p>
<p class="p2"><br></p>
<p class="p4"><b>WeaklyNonlinear.ar(input,reset, ratex,ratey,freq,initx,inity,alpha, xexponent, beta, yexponent, mul, add)</b></p>
<p class="p5"><br></p>
<p class="p4">Naive Euler ODE solver implementation of the Weakly Nonlinear Oscillator with external perturbation (see Strogatz, Steven H. (1994) Nonlinear Dynamics and Chaos. Addison-Wesley, Reading, MA. pp215 or Pikovsky, Arkady., Rosenblum, Michael., and Kurths, Jurgen. (2001). Synchronization. CUP: Cambridge. pp 189).<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">D2x +w0*w0*x = alpha*(x^xexponent*+beta)*y^yexponent<span class="Apple-converted-space">  </span>+ input</p>
<p class="p5"><br></p>
<p class="p4">y= Dx</p>
<p class="p5"><br></p>
<p class="p4">The nonlinear term is not calculated if alpha is zero. Otherwise it is generated at additional CPU cost.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">All inputs can have .kr rate UGens plugged in.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><b>input</b>- audio rate input, acts as external force</p>
<p class="p4"><b>reset</b>- restart</p>
<p class="p4"><b>ratex</b>- update rate for x</p>
<p class="p4"><b>ratey</b>- update rate for y<span class="Apple-converted-space"> </span></p>
<p class="p4"><b>freq</b>- The equation constant w0 (linear oscillator's frequency when alone * 2pi)</p>
<p class="p4"><b>initx</b>- reset value for u</p>
<p class="p4"><b>inity</b>- reset value for w</p>
<p class="p5"><br></p>
<p class="p4">NOTE: Due to an error of implementation this oscillator has an additional distortion component in it- which adds to the sound! WeaklyNonlinear2 is an implementation with this fixed, but this older version is retained for backwards compatibility and because it has an interesting roughness.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p6">//Can be very noisy, high pitched and aliases badly- ie great fun, but watch out for your ears, filter, try out odd param settings. I've turned all the amplitudes down in the following</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//defaults, high pitched! WARNING</p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">SinOsc</span>.ar(<span class="s1">MouseX</span>.kr(100,400),0,0.1)),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">SinOsc</span>.ar(<span class="s1">MouseX</span>.kr(50,1000,<span class="s2">'exponential'</span>),0,0.1),0,1,1,<span class="s1">MouseY</span>.kr(50,1000,<span class="s2">'exponential'</span>)),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//with reset</p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">SinOsc</span>.ar(<span class="s1">MouseX</span>.kr(50,1000,<span class="s2">'exponential'</span>),0,0.1),<span class="s1">Impulse</span>.kr(3),1,1,<span class="s1">MouseY</span>.kr(50,1000,<span class="s2">'exponential'</span>), <span class="s1">LFNoise0</span>.kr(1,0.4,0.5),<span class="s1">LFNoise0</span>.kr(1,10.4,10.5)),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//MouseY controls input strength of forcing oscillator</p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">Saw</span>.ar(261.626,<span class="s1">MouseY</span>.kr(0.0001,1,<span class="s2">'exponential'</span>)), freq:<span class="s1">MouseX</span>.kr(100,400)),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//2 per second</p>
<p class="p8">(</p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(</p>
<p class="p7"><br></p>
<p class="p9">CombN<span class="s3">.ar(</span></p>
<p class="p8"><span class="s1">Resonz</span>.ar(<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">Saw</span>.ar(<span class="s1">MouseX</span>.kr(50,2000,<span class="s2">'exponential'</span>),0.5),0,1,1,<span class="s1">MouseY</span>.kr(100,4000,<span class="s2">'exponential'</span>)),1000,0.1),</p>
<p class="p8">0.05,0.05,1</p>
<p class="p8">)</p>
<p class="p8">,0.0))}.play</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//with non zero nonlinear term, van der Pol equation, acts to damp, so a rest is needed to hear many sounds</p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">SinOsc</span>.ar(<span class="s1">MouseX</span>.kr(10,2000),0,0.1),<span class="s1">Impulse</span>.kr(<span class="s1">MouseY</span>.kr(0,100)),1,1,440,0,0,-0.01,2,-1,1),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p1">//Duffing equation</p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">SinOsc</span>.ar(<span class="s1">MouseX</span>.kr(1,1000,<span class="s2">'exponential'</span>),0,0.1),0,1,1,<span class="s1">MouseY</span>.kr(1,1000,<span class="s2">'exponential'</span>),0,0,-0.001,3,0,0),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//make one up... will last for a while then be lost- needs a Trigger control in reset, very aliased</p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">SinOsc</span>.ar(<span class="s1">MouseX</span>.kr(1,100,<span class="s2">'exponential'</span>),0,0.1),<span class="s1">Impulse</span>.kr(0.5),1,1,<span class="s1">MouseY</span>.kr(1,1000,<span class="s2">'exponential'</span>),LFNoise0.kr(10,0.0),LFNoise0.kr(10,0.0),0.005,3,1,0.5),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p1">//highly aliased</p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">SinOsc</span>.ar(0,0,0.1),0,1,1,<span class="s1">MouseX</span>.kr(110,880,<span class="s2">'exponential'</span>),0,0,<span class="s1">MouseY</span>.kr(0,1.0)),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//anything happening?<span class="Apple-converted-space"> </span></p>
<p class="p8">{<span class="s1">Out</span>.ar(0,<span class="s1">Pan2</span>.ar(0.1*<span class="s1">WeaklyNonlinear</span>.ar(<span class="s1">SinOsc</span>.ar(0,0,0.1),<span class="s1">Impulse</span>.kr(10),1,1,<span class="s1">MouseX</span>.kr(110,880,<span class="s2">'exponential'</span>),0,0,0.5,1,1,<span class="s1">MouseY</span>.kr(0,1.0)),0.0))}.play</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
</body>
</html>
